package com.competition.reception.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.competition.reception.entity.Module;
import com.competition.reception.entity.vo.ModuleQueryVo;
import com.competition.reception.entity.vo.ModuleResultVo;
import com.competition.reception.entity.vo.QueryVo;
import com.competition.reception.mapper.ModuleMapper;
import com.competition.reception.service.ModuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.competition.servicebase.exceptionhandler.MyException;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 投稿信息表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-04-03
 */
@Service
public class ModuleServiceImpl extends ServiceImpl<ModuleMapper, Module> implements ModuleService {

    //设置审核是否通过
    @Override
    public void statusManage(String id,Integer status) {
        QueryWrapper<Module> queryWrapper=new QueryWrapper<>();
        Module module=new Module();

        module.setStatus(status);
        module.setId(id);
        int i = baseMapper.updateById(module);
        if(i!=1) throw new MyException(20001,"审核失败");
    }

    //根据条件查询
    @Override
    public Map<String,Object> selectByConditions(ModuleQueryVo queryVo) {
        List<ModuleResultVo> resultVos = baseMapper.selectByConditions(queryVo);
        int moduleCount = baseMapper.getModuleCount(queryVo);
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("resultVos",resultVos);
        resultMap.put("moduleCount",moduleCount);
        return resultMap;
    }
}
